package cn.com.dealme.modules;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.ioc.annotation.InjectName;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.zzm.util.RandImgCreater;

import cn.com.dealme.Keys;

@InjectName("CommonModule")
public class CommonModule {

	private static final Log log = Logs.getLog(CommonModule.class);

	private HttpServletRequest req;
	private HttpServletResponse resp;
	
	/**
	 * 提供验证码图片入口
	 */
	@At("/checkcode-image")
	public void checkCode() {
		
		try {
			OutputStream os = resp.getOutputStream();
			RandImgCreater creater = new RandImgCreater(os, 4, null);
			req.getSession().setAttribute(Keys.CheckCode, creater.createRandImage());
			os.flush();
		} catch (IOException e) {
			log.error(e, e);
		}
	}

	public HttpServletRequest getReq() {
		return req;
	}

	public void setReq(HttpServletRequest req) {
		this.req = req;
	}

	public HttpServletResponse getResp() {
		return resp;
	}

	public void setResp(HttpServletResponse resp) {
		this.resp = resp;
	}
}
